package labox.innovation.gameserver.rank;

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import labox.innovation.config.Config;

/**
 * ��ʱ����
 * @author Frank
 *
 */
public class RankTask {
	private static final Logger _log = LoggerFactory.getLogger(RankTask.class.getName());
	
	private static final long PERIOD_DAY = 24 * 60 * 60 * 1000;  //-- һ��ִ��һ��
	
	private static RankTask instance = new RankTask();
	
	private RankTask() {
		
	}
	
	public static RankTask getInstance() {
		return instance;
	}
	
	@SuppressWarnings("deprecation")
	public void getStart() {
		_log.info("���������������а����", Config.SERVER_ID, "���а�");
		RankManager.getInstance().buildRanks();  //-- ��һ����������һ�����
		Calendar cd = Calendar.getInstance(); 
		cd.add(Calendar.DATE, 1);
		Date date = cd.getTime();
		date.setHours(2);
		date.setMinutes(0);
		date.setSeconds(0);
		Timer timer = new Timer();
		timer.schedule(new Task(), date, PERIOD_DAY);
	}
	
	/**
	 * ��ʱ����
	 * @author Frank
	 *
	 */
	private class Task extends TimerTask {
		public void run() {
			_log.info("ִ�����а�ʱ������", Config.SERVER_ID, "���а�");
			RankManager.getInstance().buildRanks();
		}
	}
}
